﻿using log4net;
using System;
using System.Reflection;

namespace gt.framework.Log
{
    public class FileLogWrapper : ILogWrapper
    {
        ILog m_logger = null;

        public FileLogWrapper(string loggerName)
        {
            this.m_logger = log4net.LogManager.GetLogger(loggerName);
        }
        public FileLogWrapper()
        {
            this.m_logger = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        }

        public string Name
        {
            get { return this.m_logger.Logger.Name; }
        }

        public void Debug(string msg)
        {
            if (this.m_logger.IsDebugEnabled)
                this.m_logger.Debug(msg);
        }

        public void Error(string errorMsg, Exception ex)
        {
            if (this.m_logger.IsErrorEnabled)
                this.m_logger.Error(errorMsg, ex);
        }

        public void Error(Exception ex)
        {
            Error(string.Empty, ex);
        }

        public void Error(string errorMsg)
        {
            if (this.m_logger.IsErrorEnabled)
                this.m_logger.Error(errorMsg);
        }

        public void Info(string msg)
        {
            if (this.m_logger.IsInfoEnabled)
                this.m_logger.Info(msg);
        }

        public void Warn(string msg)
        {
            if (this.m_logger.IsWarnEnabled)
                this.m_logger.Warn(msg);
        }
    }
}
